package xw.qxypt.modules.baseinfo.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import xw.qxypt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xw.qxypt.modules.baseinfo.entity.LhpRoleWaysectRelationEntity;
import xw.qxypt.modules.baseinfo.service.LhpRoleWaysectRelationService;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * 角色路段对应关系表
 *
 * @author xw
 * @email 
 * @date 2019-12-19 15:24:39
 */
@RestController
@RequestMapping("baseinfo/lhprolewaysectrelation")
public class LhpRoleWaysectRelationController {
    @Autowired
    private LhpRoleWaysectRelationService lhpRoleWaysectRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("baseinfo:lhprolewaysectrelation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = lhpRoleWaysectRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("baseinfo:lhprolewaysectrelation:info")
    public R info(@PathVariable("id") String id){
        LhpRoleWaysectRelationEntity lhpRoleWaysectRelation = lhpRoleWaysectRelationService.getById(id);

        return R.ok().put("lhpRoleWaysectRelation", lhpRoleWaysectRelation);
    }

    /**
     * 查询角色下路段信息
     */
    @RequestMapping("/getByRoleId/{roleId}")
    public R getByRoleId(@PathVariable("roleId") String roleId){

        List<LhpRoleWaysectRelationEntity> list=lhpRoleWaysectRelationService.getByRoleId(roleId);
        return R.ok().put("list", list);
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("baseinfo:lhprolewaysectrelation:save")
    public R save(@RequestBody LhpRoleWaysectRelationEntity lhpRoleWaysectRelation){
        lhpRoleWaysectRelationService.save(lhpRoleWaysectRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("baseinfo:lhprolewaysectrelation:update")
    public R update(@RequestBody LhpRoleWaysectRelationEntity lhpRoleWaysectRelation){
        ValidatorUtils.validateEntity(lhpRoleWaysectRelation);
        lhpRoleWaysectRelationService.updateById(lhpRoleWaysectRelation);
        
        return R.ok();
    }

    /**
     * 批量修改关联关系
     */
    @RequestMapping("/updateRelation")
    public R updateRelation(@RequestParam Map<String, Object> params){
        lhpRoleWaysectRelationService.updateRelation(params);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("baseinfo:lhprolewaysectrelation:delete")
    public R delete(@RequestBody String[] ids){
        lhpRoleWaysectRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
